/****************************************************************************
*														                    *
* drawstate.h -- template state implementation					            *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/
#pragma once

#if !defined(__DRAWSTATE_H)
#define __DRAWSTATE_H

#include "../../common/defs.h"
#include "../../common/singleton.h"
#include <QEvent>
#include <QMouseEvent>
#include <QPainter>

/****************************************************************************
* Forward declarations										 				*
****************************************************************************/
class CDrawManager;
/****************************************************************************
* CDrawState												 				*
****************************************************************************/
class CDrawState 
{
public :
	enum eState
	{
		eIdleState,
		eDrawingState,
	};

	~CDrawState()
	{}

	inline const eState& state() const { return m_state; }

	virtual void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent) = 0;

	eState		m_state;

protected :
	CDrawState(const eState& rState = CDrawState::eIdleState) :
		m_state(rState)
	{}

	void changeState(CDrawManager *pDrawManager,  CDrawState *pState)
	{ pDrawManager->changeState(pState); }

};

/****************************************************************************
* CDrawStateIdle												 			*
****************************************************************************/
class CDrawStateIdle : 
	public CDrawState, 
	public CSingleton<CDrawStateIdle>
{
	friend class CSingleton<CDrawStateIdle>;

public :
	void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent);  

	static CDrawStateIdle* inst() 
		{ return (dynamic_cast<CDrawStateIdle*>(getInstance())); } 

	void destroy() { destroyInstance(); }

private :
	CDrawStateIdle()
		: CDrawState()
	{}
	
	~CDrawStateIdle()
	{}
};

/****************************************************************************
* CDrawStateRect												 			*
****************************************************************************/
class CDrawStateRect : 
	public CDrawState, 
	public CSingleton<CDrawStateRect>
{
	friend class CSingleton<CDrawStateRect>;

public :
	static CDrawStateRect* inst() 
		{ return (dynamic_cast<CDrawStateRect*>(getInstance())); } 

	void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent);  

	void destroy() { destroyInstance(); }


private :
	CDrawStateRect() 
		: CDrawState(CDrawState::eDrawingState)
	{}

	~CDrawStateRect()
	{}

	QPoint		m_pointStart;
	QPoint		m_pointEnd;
};

/****************************************************************************
* CDrawStateLine												 			*
****************************************************************************/
class CDrawStateLine : 
	public CDrawState, 
	public CSingleton<CDrawStateLine>
{
	friend class CSingleton<CDrawStateLine>;

public :
	static CDrawStateLine* inst() 
		{ return (dynamic_cast<CDrawStateLine*>(getInstance())); } 

	void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent);  

	void destroy() { destroyInstance(); }

private :
	CDrawStateLine()
		: CDrawState(CDrawState::eDrawingState)
	{}

	~CDrawStateLine()
	{}

	QPoint		m_pointStart;
	QPoint		m_pointEnd;
};

/****************************************************************************
* CDrawStateEllipse												 			*
****************************************************************************/
class CDrawStateEllipse : 
	public CDrawState,
	public CSingleton<CDrawStateEllipse>
{
	friend class CSingleton<CDrawStateEllipse>;

public :
	static CDrawStateEllipse* inst() 
		{ return (dynamic_cast<CDrawStateEllipse*>(getInstance())); } 

	void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent);  

	void destroy() { destroyInstance(); }

private :
	CDrawStateEllipse() 
		: CDrawState(CDrawState::eDrawingState)
	{}

	~CDrawStateEllipse()
	{}

	QPoint		m_pointStart;
	QPoint		m_pointEnd;

};

/****************************************************************************
* CDrawStatePoint												 			*
****************************************************************************/
class CDrawStatePoint : 
	public CDrawState,
	public CSingleton<CDrawStatePoint>
{
	friend class CSingleton<CDrawStatePoint>;

public :
	void processEvent(CDrawManager *pDrawManager,  QEvent *pEvent);  

	static CDrawStatePoint* inst() 
		{ return (dynamic_cast<CDrawStatePoint*>(getInstance())); } 

	void destroy() { destroyInstance(); }

private :
	CDrawStatePoint() 
		: CDrawState(CDrawState::eDrawingState)
	{}

	~CDrawStatePoint()
	{}
};

#endif /* __DRAWSTATE_H */
/****************************************************************************
* End of file																*
****************************************************************************/
